package com.zkgengkun.job;

import com.dangdang.ddframe.job.api.ShardingContext;
import com.dangdang.ddframe.job.api.simple.SimpleJob;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>
 *
 * </p>
 *
 * @author Shik
 * @project springboot
 * @package com.zkgengkun.job
 * @since 2019-01-14
 */
public class SimpleDemoJob implements SimpleJob {
    @Override
    public void execute(ShardingContext context) {
        System.out.println(2 / 0);
        String shardParamter = context.getShardingParameter();
        System.out.println("分片参数：" + shardParamter);
        int value = Integer.parseInt(shardParamter);
        for (int i = 0; i < 1000000; i++) {
            if (i % 2 == value) {
                String time = new SimpleDateFormat("HH:mm:ss").format(new Date());
                System.out.println(time + ":开始执行简单任务" + i);
            }
        }
        switch (context.getShardingItem()) {
            case 0:
                // do something by sharding item 0
                break;
            case 1:
                // do something by sharding item 1
                break;
            case 2:
                // do something by sharding item 2
                break;
            // case n: ...
        }
    }
}
